package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

import java.util.Objects;

/**
 * <Description> <br>
 *  路由协议类型
 * @author cheng.leizhen01<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2021年3月14日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.attr.handler <br>
 */

public class RouteProtocolTypeAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    // 业务变更  附加产品  ‘路由协议类型’，‘本地电路代号’，‘一站式业务流水号’，‘上联机房’，‘计费带宽’，‘分公司’，‘用户地址是否需要广播’，‘是否大带宽’ 不可修改
    @Override
    public void before(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        super.before(attr, inst, value, data);
        String  servicOfferId = data.getServiceOfferId();
        if(KiteStringUtils.isNotEmpty(servicOfferId) && KiteStringUtils.equals("1024",servicOfferId)) {
            String dcPublic = DcPublicCache.get("2020032601", ProdCateUtil.getSingleCateId(ProdCateUtil.DIA_CODE)).getCodea();
            if (KiteStringUtils.isNotEmpty(dcPublic)) {
                String[] arrAttr = dcPublic.split(",");
                KiteAttr tempAttr;
                for (int i = 0; i < arrAttr.length; i++) {
                    tempAttr = inst.getAttr(arrAttr[i]);
                    if (Objects.nonNull(tempAttr)) {
                        tempAttr.setIsEdit("F");
                    }
                }
            }
        }
    }
}
